package com.bzy.blp.upms.web.controller;


import com.bzy.blp.upms.service.PermissionService;
import com.bzy.blp.upms.vo.RoleResourceVO;
import com.bzy.common.bean.Result;
import com.bzy.common.validator.Validator;
import com.bzy.common.validator.annotation.ValidateParam;
import com.bzy.shiro.util.SessionUtil;
import com.wordnik.swagger.annotations.ApiParam;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import javax.servlet.http.HttpServletRequest;
import java.util.List;

@RestController
@RequestMapping(value = "/permission")
public class PermissionController {

    @Autowired
    PermissionService permissionService;

    /**
     * 获取角色列表（附加权限列表）
     * @param appKey
     * @param request
     * @return
     * @throws Exception
     */
    @GetMapping(value = "/getRolePermissionList")
    public Result getRolePermissionList(
            @ApiParam(value = "appKey", required = true) @ValidateParam({Validator.NOT_BLANK}) String appKey, HttpServletRequest request) throws Exception {
        Result result = new Result();
        String userId = SessionUtil.getAccountId();
        List<RoleResourceVO> permissionList = permissionService.findRolePermissionList(Long.parseLong(userId), appKey);
        result.setData(permissionList);
        return result;
    }


}
